<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <div id="div1"></div>

    <script>
        var div=document.querySelector('#div1');
        //on+事件名，传统注册事件注册在事件冒泡阶段
        // div.onclick=function(){
        //     alert('单击');
        // }
        // document.body.onclick=function(){
        //     alert('ok')
        // }
        div.addEventListener('click',function(){
            alert('单击');
        },true);
        document.body.addEventListener('click',function(){alert('ok');},true);
    </script>
</body>
</html>